Add startup timeout to prevent gateway hanging on unresponsive MCP servers#477
Merged
Add startup timeout to prevent gateway hanging on unresponsive MCP servers#477
Conversation
Co-authored-by: lpcox <15877973+lpcox@users.noreply.github.com>
Co-authored-by: lpcox <15877973+lpcox@users.noreply.github.com>
Use goroutine with timeout channel instead of context.WithTimeout to prevent connection from being canceled after successful startup. Co-authored-by: lpcox <15877973+lpcox@users.noreply.github.com>
Eliminates code duplication by defining connectionResult once at the package level instead of duplicating it in both GetOrLaunch() and GetOrLaunchForSession().
The buffered channel with size 1 allows the goroutine to complete even if timeout occurs first, preventing goroutine leaks. Co-authored-by: lpcox <15877973+lpcox@users.noreply.github.com>
Replace magic numbers with package-level constants (DefaultStartupTimeout, DefaultToolTimeout, DefaultPort) to maintain consistency and avoid duplication. Co-authored-by: lpcox <15877973+lpcox@users.noreply.github.com>
Copilot
AI
changed the title
[WIP] Fix gateway to handle dangling mcp servers
Add startup timeout to prevent gateway hanging on unresponsive MCP servers
Jan 26, 2026
This was referenced Jan 26, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Gateway would hang indefinitely during initialization if any backend MCP server failed to respond, blocking all other backends from starting.
Changes
Configuration: Added
startupTimeoutfield (default: 60s) to gateway config with package-level constants (DefaultStartupTimeout,DefaultToolTimeout,DefaultPort).Timeout enforcement: Implemented goroutine + buffered channel pattern in
GetOrLaunch()andGetOrLaunchForSession():Graceful degradation: Failed backends log warnings and gateway continues initialization with remaining backends.
Technical decisions
time.After()instead ofcontext.WithTimeoutto avoid canceling connection after successful startupWarning
Firewall rules blocked me from connecting to one or more addresses (expand for details)
I tried to connect to the following addresses, but was blocked by firewall rules:
nonexistent.local/tmp/go-build3377049250/b269/launcher.test /tmp/go-build3377049250/b269/launcher.test -test.testlogfile=/tmp/go-build3377049250/b269/testlog.txt -test.paniconexit0 -test.timeout=10m0s -test.v=true go user.email t[bot](dns block)/tmp/go-build481144272/b273/launcher.test /tmp/go-build481144272/b273/launcher.test -test.testlogfile=/tmp/go-build481144272/b273/testlog.txt -test.paniconexit0 -test.timeout=10m0s -test.v=true dleware.test /tmp/go-build3677275879/b097/ ortcfg.link . --gdwarf2 --64 GL0vaMStIAuGbawbr5/sWo5QoaFO32xMT3YHtp6/k1XMsJiotFONAaFTgZJc(dns block)/tmp/go-build3502506537/b273/launcher.test /tmp/go-build3502506537/b273/launcher.test -test.testlogfile=/tmp/go-build3502506537/b273/testlog.txt -test.paniconexit0 -test.timeout=10m0s -test.v=true -lang=go1.25 docker-buildx x_amd64/vet se 7049250/b028/vetls-files x_amd64/cgo x_amd64/vet 791 6791 791 aw-mcpg/awmg se 7049250/b141/vet-c x_amd64/vet aw-mcpg/awmg(dns block)this-host-does-not-exist-12345.com/tmp/go-build3377049250/b278/mcp.test /tmp/go-build3377049250/b278/mcp.test -test.testlogfile=/tmp/go-build3377049250/b278/testlog.txt -test.paniconexit0 -test.timeout=10m0s -test.v=true g_.a --global rgo/bin/bash credential.helpe/opt/hostedtoolcache/go/1.25.6/x64/pkg/tool/linux_amd64/vet(dns block)If you need me to access, download, or install something from one of these locations, you can either:
Original prompt
✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.